package sz.szsmk.citizencard.mvp.presenter;

import rx.functions.Action1;
import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.UserBehaviorBrowseReq;
import sz.szsmk.citizencard.model.network.bean.request.WeathDetailReq;
import sz.szsmk.citizencard.model.network.bean.response.BaseBean;
import sz.szsmk.citizencard.model.network.bean.response.WeathDetailRes;
import sz.szsmk.citizencard.mvp.contract.IHomeWeathContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.AndroidUtils;

import javax.inject.Inject;

/**
 * Copyright (c)2018
 * 欣网互联网络科技有限公司
 * author: zdh
 * created on: 2018/8/10 11:31
 * description:
 */
public class WeathPresenter extends IBasePresenter
        implements IHomeWeathContact.IHomeWeathPresenter<IHomeWeathContact.IHomeWeathView> {

    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public WeathPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    @Override
    public void getWeathFore() {
        WeathDetailReq weathDetailReq = new WeathDetailReq();
        weathDetailReq.setCityName("虎丘区");
        mNetworkDateSource.getWeathFore(weathDetailReq, new SubscribeResult<WeathDetailRes>() {
            @Override
            protected void onOk(WeathDetailRes response) {

                ((IHomeWeathContact.IHomeWeathView) mView).delWeathForeSuccess(response);
            }

            @Override
            protected void onFailure(WeathDetailRes response) {
                super.onFailure(response);
                ((IHomeWeathContact.IHomeWeathView) mView).getWeathForeError(response.getMessage());
            }

            @Override
            protected void onNext(WeathDetailRes response) {
                super.onNext(response);
                ((IHomeWeathContact.IHomeWeathView) mView).getWeathForeError(response.getMessage());
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
                ((IHomeWeathContact.IHomeWeathView) mView).getWeathForeError(throwable.getMessage());

            }
        });

    }
    public void userBehaviorBrowse() {
        UserBehaviorBrowseReq userBehaviorBrowseReq = new UserBehaviorBrowseReq();
        userBehaviorBrowseReq.setModularId(42);
        userBehaviorBrowseReq.setAccessToken(ACache.get(DaggerApplication.getIns()).getAsString("access_token"));

        mNetworkDateSource.userBehaviorBrowse(userBehaviorBrowseReq, new Action1<BaseBean>() {
            @Override
            public void call(BaseBean baseBean) {
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }
}
